<?php
/**
 * Created by PhpStorm.
 * User: liyu
 * Date: 2018/4/19
 * Time: 下午5:51
 */

namespace app\worker\controller;


use app\common\controller\Curl;
use app\common\service\worker\WorkerBase;
use think\Log;

class Work extends WorkerBase
{
    protected function runHandle($data)
    {
        try{
            while ( true ){
                Curl::get( "http://www.baidu.com/");
                $time = $this->getNextRunTime();
                $this->sleep($time);
                Log::notice("循环执行程序执行程序".time() );
            }
        }catch (\Exception $e){
            Log::notice( $e ->getMessage());
        }
    }

    protected function getNextRunTime(){
        if (time()<strtotime( "02:00") ){
            return 15;
        }elseif(time()<strtotime( "09:57") ){
            return 180;
        }elseif(time()<strtotime( "22:00") ){
            return 30;
        }elseif(time()<strtotime( "23:59") ){
            return 15;
        }
        return 60;
    }
}